/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

function test (data){
  return new Promise ((resolve,reject)=>{
    setTimeout(() => resolve(data),10)
  })
}

function * mainCode () {
  try {
    const a = yield test('hello');
    const b = yield test('lagou');
    const c = yield test('I ♥ U');
    console.log(a + b +c)
  } catch (error) {
    console.log(error)
  }

}

function textCode (dataFunc){
  const func = dataFunc();
  function extec(result){
    if(!result.done){
      result.value.then(data => extec(func.next(data)));
    }
  }
  extec(func.next());
  
}

textCode(mainCode);


